package com.learn.atomic;

import java.util.concurrent.atomic.AtomicReferenceFieldUpdater;

/**
 * @author ln
 * @Description: ${todo}
 * @date 2020/12/21
 */
public class TestUpdater {
    public static void main(String[] args) {
        Student student = new Student();

        AtomicReferenceFieldUpdater<Student, String> fieldUpdater =
                AtomicReferenceFieldUpdater.newUpdater(Student.class, String.class, "name");

        System.out.println(fieldUpdater.compareAndSet(student, null, "张三"));
        System.out.println(student);

    }
}

class Student{
    volatile String name;

    @Override
    public String toString() {
        return "Student{" +
                "name='" + name + '\'' +
                '}';
    }
}
